﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Goway.StackingUC.Entity
{
    /// <summary>
    /// 物料记录
    /// </summary>
    public class MaterialRecord
    {
        public List<MaterialInfo> materials;

        /// <summary>
        /// 获得物料信息
        /// </summary>
        /// <returns></returns>
        public List<MaterialInfo> GetMaterials()
        {
            if(materials != null && materials.Count > 0)
            {
                return materials;
            }

            materials = new List<MaterialInfo>();
            MaterialInfo record1 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[0, 0],
                ColumnIndex = Coordinate.InputBufferCoord[0, 1],
                LayerIndex = Coordinate.InputBufferCoord[0, 2],
                AtLocation = GetAtLocation(0),
                index = 1,
                MaterialBar = "NGUA29L4R9REF3O0000B230706N508B100635",
                MaterialType = "5NA+23.54M10B9B2"
            };

            materials.Add(record1);

            MaterialInfo record2 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[1, 0],
                ColumnIndex = Coordinate.InputBufferCoord[1, 1],
                LayerIndex = Coordinate.InputBufferCoord[1, 2],
                AtLocation = GetAtLocation(1),
                index = 2,
                MaterialBar = "NGUA29L4R9REF1O7935G230706N508A130634",
                MaterialType = "5NA+23.54M10B9B1"
            };

            materials.Add(record2);

            MaterialInfo record3 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[2, 0],
                ColumnIndex = Coordinate.InputBufferCoord[2, 1],
                LayerIndex = Coordinate.InputBufferCoord[2, 2],
                AtLocation = GetAtLocation(2),
                index = 3,
                MaterialBar = "NGUA29L4R9REF1O7844G230706N610B130631",
                MaterialType = "5NA+23.54M10B9B0"
            };

            materials.Add(record3);

            MaterialInfo record4 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[3, 0],
                ColumnIndex = Coordinate.InputBufferCoord[3, 1],
                LayerIndex = Coordinate.InputBufferCoord[3, 2],
                AtLocation = GetAtLocation(3),
                index = 4,
                MaterialBar = "NGUA29L4R9REF1O7935G230706N610B130634",
                MaterialType = "5NA+23.47M10B9A1"
            };

            materials.Add(record4);

            MaterialInfo record5 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[4, 0],
                ColumnIndex = Coordinate.InputBufferCoord[4, 1],
                LayerIndex = Coordinate.InputBufferCoord[4, 2],
                AtLocation = GetAtLocation(4),
                index = 5,
                MaterialBar = "NGUA29L4R9REF1O7896G230706N508A130639",
                MaterialType = "5NA+23.54M10B9B1"
            };

            materials.Add(record5);

            MaterialInfo record6 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[5, 0],
                ColumnIndex = Coordinate.InputBufferCoord[5, 1],
                LayerIndex = Coordinate.InputBufferCoord[5, 2],
                AtLocation = GetAtLocation(5),
                index = 6,
                MaterialBar = "NGUA29L4R9REF2O7895A230706N507B130638",
                MaterialType = "3NA+23.75M10B9B2"
            };

            materials.Add(record6);

            MaterialInfo record7 = new MaterialInfo()
            {
                RowIndex = Coordinate.InputBufferCoord[6, 0],
                ColumnIndex = Coordinate.InputBufferCoord[6, 1],
                LayerIndex = Coordinate.InputBufferCoord[6, 2],
                AtLocation = GetAtLocation(6),
                index = 7,
                MaterialBar = "NGUA29L4R9REF1O7935G230706N508B130639",
                MaterialType = "0NB30.00B9B0"
            };

            materials.Add(record7);

            return materials;
        }

        /// <summary>
        /// 位置信息
        /// </summary>
        /// <param name="idx"></param>
        /// <returns></returns>
        private string GetAtLocation(int idx)
        {
            if (idx < 0 && idx >= 7)
            {
                return "";
            }

            string atLocation = Coordinate.InputBufferCoord[idx, 0].ToString() + ", " +
                Coordinate.InputBufferCoord[idx, 1].ToString() + ", " +
                Coordinate.InputBufferCoord[idx, 2].ToString();

            return atLocation;
        }
    }
}
